const router = require('koa-router')();
const fs = require('fs-extra');
const path = require('path');
const {dataPath} = require('../config');

/**
 * 页面服务
 */
router.get('/',async(ctx) => {
    ctx.body = await fs.readFile(path.join(__dirname,'../public','answer.html'),'utf8');
})

router.get('/count',async(ctx) => {
    try {
        const data = await fs.readFile(dataPath);
        ctx.body = {
            code:1,
            msg:'success',
            data: JSON.parse(data)
        }
    }catch(error){
        ctx.body = {
            code:1,
            msg:'error'
        }
        ctx.status = 500;
    }
})

module.exports = router;